package com.feng.chat.controller;

import com.feng.chat.dto.Result;
import com.feng.chat.service.IEmoticonService;
import com.feng.chat.utils.GetUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/v1/emoticon")
public class EmoticonController {
    @Autowired
    private IEmoticonService emoticonService;

    /**
     * 获取用户表情包数据
     * @param request
     * @return
     */
    @GetMapping("/list")
    public Result list(HttpServletRequest request){
        Integer userId = GetUserUtil.getUserId(request);
        Result result = emoticonService.emoticonList(userId);
        return result;
    }

    /**
     * 自定义表情包
     * @param request
     * @param emoticon
     * @return
     */
    @PostMapping("/customize/create")
    public Result customizeCreate(HttpServletRequest request, @RequestBody MultipartFile emoticon){
        Integer userId = GetUserUtil.getUserId(request);
        Result result = emoticonService.customizeCreate(userId, emoticon);
        return result;
    }

    /**
     * 获取系统表情包列表
     * @param request
     * @return
     */
    @GetMapping("/system/list")
    public Result systemList(HttpServletRequest request){
        Integer userId = GetUserUtil.getUserId(request);
        Result result = emoticonService.systemList(userId);
        return result;
    }

    /**
     * 添加系统表情包
     * @param request
     * @param map
     * @return
     */
    @PostMapping("/system/install")
    public Result systemInstall(HttpServletRequest request, @RequestBody Map<String,Integer> map){
        Integer userId = GetUserUtil.getUserId(request);
        Result result = emoticonService.systemInstall(userId,map.get("type"), map.get("emoticon_id"));
        return result;
    }
}
